package com.itheima.tlias84.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 统计接口耗时切面
 */
@Aspect
@Component
@Slf4j
public class CountTimeAspect {

    @Around("execution(* com.itheima.tlias84.service.impl.*.*(..))")
    public Object count(ProceedingJoinPoint point) {

        long start = System.currentTimeMillis();

        try {
            Object proceed = point.proceed();
            long end = System.currentTimeMillis() - start;
            log.info("{}接口耗时：{}ms", point.getSignature().getName(), end);
            return proceed;
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }

}
